<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2007 osCommerce

  Released under the GNU General Public License
*/

  include('includes/application_top.php');
  
  $path = DIR_FS_CATALOG . DIR_WS_images . 'images-i/';
  
  $products_query = tep_db_query("select products_id, products_model, products_image from products where products_model != ''");
  while($products = tep_db_fetch_array($products_query)) {
	  if($products['products_model'] != '') {
		  $products_check_query = tep_db_query("select products_id, products_model from products where products_model like '" . $products['products_model'] . "' and products_id != '" . $products['products_id'] . "'");
		  if(tep_db_num_rows($products_check_query) > 0) {
			  $products_check = tep_db_fetch_array($products_check_query);
			  echo $products_check['products_id'] . '--' . $products_check['products_model'] . '<br>';
		  } else {
			  $path_parts = pathinfo($path . $products['products_image']);
			  $new_images = tep_db_prepare_input($products['products_model'] . '.' . $path_parts['extension']);
			  
			  if(rename($path . $products['products_image'], $path . $new_images)) {
				  tep_db_query("update products set products_image = '" . $new_images . "' where products_id = " . $products['products_id']);
			  } else {
				  echo '---rename : ' . $products_check['products_id'] . '--' . $products_check['products_model'] . '<br>';
			  }
		  }
	  }
  }

?>
